/*
 * factorial.c - many ways to calculate the factorial
 */

#include <math.h>

/*
 *      ⎧ 1 if n = 0
 * n! = ⎨                    ∀n ∈ ℵ
 *      ⎩ n((n-1)!) if n > 0
 */
long
factorial_rec(long n)
{
	if (n == 0)
		return 1;
	else
		return n * factorial_rec(n-1);
}

/*
 *      n
 * n! = ∏ k ∀n ∈ ℵ
 *     k=1
 */
long
factorial_ite(long n)
{
	long res = 1;
	long k;
	for (k=1; k <= n; k++)
		res *= k;
	return res;
}

/* Function Gamma identity: Γ(n) = n-1!  */
double
factorial_gamma(double n) { return tgamma(n+1); }
